<?php

namespace app\models\admin_ops;

use Yii;

/**
 * This is the model class for table "admin_ops_refill".
 *
 * @property int $id
 * @property int $user_id
 * @property float $balance 可以为负
 * @property float $score 可以为负,表示减掉
 * @property float $ticket 购物券, 可以为负
 * @property float $platform_ticket 平台券, 可以为负
 * @property string $create_time
 */
class AdminOpsRefill extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'admin_ops_refill';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id'], 'required'],
            [['user_id'], 'integer'],
            [['balance', 'score', 'ticket', 'platform_ticket'], 'number'],
            [['create_time'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'balance' => 'Balance',
            'score' => 'Score',
            'ticket' => 'Ticket',
            'platform_ticket' => 'Platform Ticket',
            'create_time' => 'Create Time',
        ];
    }

    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            $time = date('Y-m-d H:i:s');
            if ($insert) {
                $this->create_time = $time;
            }
            return true;
        }
        return false;
    }
}
